Bring in magellan route parsing code I'd had laying around. It's not
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 22 Oct 2002 19:11:04 +0000 (19:11 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 22 Oct 2002 19:11:04 +0000 (19:11 +0000)
hooked up to anything useful just yet.

gpsbabel/Makefile
gpsbabel/defs.h
gpsbabel/gpx.c
gpsbabel/magproto.c

index 5ed8c99fb6c4b0447f60535d7939fe39341142f6..b83592c6b33d05021989282f3b6df7a2fc08ffb5 100644 (file)
@@ -1,4 +1,4 @@
-CFLAGS=-g -Icoldsync -belf -I/usr/local/include/
+CFLAGS=-g -Icoldsync
 
 FMTS=magproto.o gpx.o geo.o gpsman.o mapsend.o mapsource.o \
        gpsutil.o tiger.o pcx.o csv.o cetus.o gpspilot.o magnav.o \
index b33ac3ff75d45890b96f8feae5ab0e52c85d07e4..da0c4f2441cb286d474f8ae0bfbbe145db4cd515 100644 (file)
@@ -118,6 +118,14 @@ typedef struct {
        geocache_data gc_data;
 } waypoint;
 
+typedef struct {
+       queue Q;                /* Link onto parent list. */
+       queue waypoint_list;    /* List of child waypoints */
+       char *rte_name;
+       char *rte_desc;
+       int rte_num;
+} route_head;
+
 typedef void (*ff_init) (char const *);
 typedef void (*ff_deinit) (void);
 typedef void (*ff_read) (void);
index 4e3b8cf931f5ec2993e49db9b4111798eca96241..87338f63c0b98a27c044774a9769a4cad03a2cfa 100644 (file)
@@ -181,7 +181,7 @@ gpx_end(void *data, const char *el)
                in_wpt--;
        }
        else if (strcmp(el, "rtept") == 0) {
-               route_add(wpt_tmp);
+/*             route_add(wpt_tmp); */
                in_rte--;
        } else if (strcmp(el, "name") == 0) {
                in_name--;
index 3c88c3f4b373ceb27e32bc47e29c8c5019640b4b..4959d00505e374ebb5563a80f87298344788078b 100644 (file)
@@ -47,6 +47,22 @@ typedef enum {
        mrs_handon
 } mag_rxstate;
 
+/*
+ *   An individual element of a route.
+ */
+typedef struct mag_rte_elem {
+       queue Q;                        /* My link pointers */
+       char *wpt_name;
+       char *wpt_icon;
+} mag_rte_elem;
+
+/*
+ *  A header of a route.  Related elements of a route belong to this.
+ */
+typedef struct mag_rte_head {
+       queue Q;                        /* Queue head for child rte_elems */
+       int nelems;
+} mag_rte_head;
 
 static FILE *magfile_in;
 static FILE *magfile_out;
@@ -675,7 +691,91 @@ mag_trkparse(char *trkmsg)
        
 }
 
+/*
+ * Given an incoming route messages of the form:
+ * $PMGNRTE,4,1,c,1,DAD,a,Anna,a*61
+ * generate a route.
+ */
+waypoint * 
+mag_rteparse(char *rtemsg)
+{
+       char descr[100];
+       int n;
+       int frags,frag,rtenum;
+       char xbuf[100],next_stop[100],abuf[100];
+       char *currtemsg;
+       static mag_rte_head *mag_rte_head;
+       mag_rte_elem *rte_elem;
+
+       descr[0] = 0;
+
+       sscanf(rtemsg,"$PMGNRTE,%d,%d,%c,%d%n", 
+               &frags,&frag,xbuf,&rtenum,&n);
+
+       /*
+        * This is the first component of a route.  Allocate a new
+        * queue head.   It's kind of unfortunate that we can't know
+        * a priori how many items are on this track, so we have to
+        * alloc and chain those as we go.
+        */
+       if (frag == 1) {
+               mag_rte_head = xmalloc(sizeof (*mag_rte_head));
+               QUEUE_INIT(&mag_rte_head->Q);
+               mag_rte_head->nelems = frags;
+       }
+
+       currtemsg = rtemsg + n;
 
+       /*
+        * The individual line may contain several route elements.
+        * loop and pick those up.
+        */
+       while (sscanf(currtemsg,",%[^,],%[^,]%n",next_stop, abuf,&n)) {
+               if (next_stop[0] == 0) {
+                       break;
+               }
+               rte_elem = xmalloc(sizeof (*rte_elem));
+               QUEUE_INIT(&rte_elem->Q);
+               rte_elem->wpt_name = xstrdup(next_stop);
+               rte_elem->wpt_icon = xstrdup(abuf);
+               ENQUEUE_TAIL(&mag_rte_head->Q, &rte_elem->Q);
+               next_stop[0] = 0;
+               currtemsg += n;
+       }
+
+       /*
+        * If this was the last fragment of the route, add it to the
+        * gpsbabel internal structs now.
+        */
+       if (frag == mag_rte_head->nelems) {
+               queue *elem, *tmp;
+               route_head *rte_head;
+
+               rte_head = route_head_alloc();
+               route_add_head(rte_head);
+
+               /*
+                *  TODO: I suppose we have to fetch the waypoints to
+                *  get the underlying data for each stop in the route.
+                */
+               QUEUE_FOR_EACH(&mag_rte_head->Q, elem, tmp) {
+                       static int lat; /* Dummy data */
+                       mag_rte_elem *re = (mag_rte_elem *) elem;
+                       waypoint *waypt;
+
+                       waypt  = xcalloc(sizeof *waypt, 1);
+
+                       /* TODO Populate rest of waypoint. */
+                       waypt->shortname = re->wpt_name;
+                       waypt->position.latitude.degrees = ++lat;
+
+                       route_add_wpt(rte_head, waypt);
+                       dequeue(&re->Q);
+                       free(re);
+               }
+       }
+       return 0;
+}
 
 const char *
 mag_find_descr_from_token(const char *token)